home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / global-one-water.swf / scripts / __Packages / Tips.as < prev   
Encoding:
Text File  |  2011-10-17  |  1.6 KB  |  74 lines

  1. class Tips extends MovieClip
  2. {
  3.    var txt;
  4.    var inner;
  5.    var queue;
  6.    var showFor;
  7.    var mode;
  8.    var shownFor;
  9.    static var BASE_WAIT = 15;
  10.    static var CHAR_WAIT = 2.2;
  11.    static var IDLE = "idle";
  12.    static var SHOWING = "showing";
  13.    static var TRANSITIONING = "transitioning";
  14.    static var SHOW = "show";
  15.    static var HIDE = "hide";
  16.    static var NEW = "new";
  17.    function Tips()
  18.    {
  19.       super();
  20.       this.txt = this.inner.txt;
  21.       this.queue = [];
  22.    }
  23.    function addMessage(str)
  24.    {
  25.       this.queue.push(str);
  26.    }
  27.    function checkMessages()
  28.    {
  29.       if(this.queue.length)
  30.       {
  31.          this.setMessage();
  32.       }
  33.    }
  34.    function setMessage()
  35.    {
  36.       this.txt.text = String(this.queue.shift());
  37.       this.showFor = Tips.BASE_WAIT + this.txt.text.length * Tips.CHAR_WAIT;
  38.       this.gotoAndPlay(Tips.SHOW);
  39.       this.mode = Tips.TRANSITIONING;
  40.    }
  41.    function showingMessage()
  42.    {
  43.       this.mode = Tips.SHOWING;
  44.       this.shownFor = 0;
  45.       this.inner.gotoAndPlay(Tips.NEW);
  46.       this.stop();
  47.    }
  48.    function hidingMessage()
  49.    {
  50.       this.gotoAndPlay(Tips.HIDE);
  51.       delete this.shownFor;
  52.       this.mode = Tips.TRANSITIONING;
  53.    }
  54.    function hiddenMessage()
  55.    {
  56.       this.mode = Tips.IDLE;
  57.       this.stop();
  58.    }
  59.    function update()
  60.    {
  61.       if(this.mode == Tips.SHOWING)
  62.       {
  63.          if(++this.shownFor >= this.showFor)
  64.          {
  65.             this.hidingMessage();
  66.          }
  67.       }
  68.       else if(this.mode == Tips.IDLE)
  69.       {
  70.          this.checkMessages();
  71.       }
  72.    }
  73. }
  74.